package com.example.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.model.Business;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface BusinessMapper extends BaseMapper<Business> {

    @Select("SELECT * FROM business")
    List<Business> getBusinessList();

    /**
     * 获取前5条业务记录
     */
    @Select("SELECT * FROM business LIMIT 5")
    List<Business> getTop5Businesses();

    @Insert("INSERT INTO business(name, type_id, owner_id, start_time, end_time, status, priority, description, create_time, update_time) " +
            "VALUES(#{name}, #{typeId}, #{ownerId}, #{startTime}, #{endTime}, #{status}, #{priority}, #{description}, #{createTime}, #{updateTime})")
    int insert(Business business);

    @Insert("UPDATE business SET name = #{name}, type_id = #{typeId}, owner_id = #{ownerId}, start_time = #{startTime}, end_time = #{endTime}, status = #{status}, priority = #{priority}, description = #{description}, update_time = #{updateTime} WHERE id = #{id}")
    int updateById(Business business);

    @Delete("DELETE FROM business WHERE id = #{id}")
    void deleteBusinessById(int id);
}
